def prosto(n):
    t=True
    for i in range (2,int(n**0.5)+1):
        if n%i==0:
            t=False
    return t

s = input()
alf = ['zero','one','two','three','four','five','six','seven','eight','nine']
s=s.split()
if (s[0] in alf) and (s[1] in alf) and (s[2] in alf):
    chisla = alf.index(s[0])*100+ alf.index(s[1])*10+ alf.index(s[2])
    if prosto(chisla):
        p=chisla
    else:
        for i in range(chisla-1,2,-1):
            if prosto(i):
                p=i
                break
        for i in range(chisla+1,1500):
            if prosto(i) and (chisla - p)>(i-chisla):
                p=i
                break
            
    print(p)
else:
    print('Wrong input')
